package yxy.game.pm2.command.conquest;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ConquestMessage;
import yxy.game.pm2.module.conquest.ConquestHandle;

/** 征战 通关奖励领取 */
@MessageType(proto = Command.ConquestBonusReceive, classtype = ConquestMessage.ConquestBonusReceiveRequest.class)
public class CMD_ConquestBonusReceive extends Command<ConquestMessage.ConquestBonusReceiveRequest> {

	@Override
	public void execute(MessageSource messageSource, ConquestMessage.ConquestBonusReceiveRequest request) {
		String playerCode = messageSource.getTag();
		int id = request.getId();

		ConquestMessage.ConquestBonusReceiveResponse.Builder response = ConquestMessage.ConquestBonusReceiveResponse.newBuilder();

		Result result = new ConquestHandle().levelReward(playerCode, id, response);

		send(messageSource, response, result);
	}

	private void send(MessageSource messageSource, ConquestMessage.ConquestBonusReceiveResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}